package com.example.demo.principle.controller;

import com.example.demo.principle.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DogController {
    @Autowired
    private ApplicationContext context;
    @Autowired
    private Dog singletonDog;
    @Autowired
    private Dog prototypeDog;
    @Autowired
    private Dog requestDog;
    @Autowired
    private Dog sessionDog;
    @Autowired
    private Dog  applicationDog;


    @RequestMapping("/single")
    public String single() {
        Dog contextDog = context.getBean("singletonDog",Dog.class);
        return "contextDog: " + contextDog + "@Autowired注入： " + singletonDog;
    }


    @RequestMapping("/prototype")
    public String prototype() {
        Dog contextDog = context.getBean("prototypeDog",Dog.class);
        return "contextDog: " + contextDog + "@Autowired注入： " + prototypeDog;
    }

    @RequestMapping("/request")
    public String request() {
        Dog contextDog = context.getBean("requestDog",Dog.class);
        return "contextDog: " + contextDog + "@Autowired注入： " + requestDog;
    }

    @RequestMapping("/session")
    public String session() {
        Dog contextDog = context.getBean("sessionDog",Dog.class);
        return "contextDog: " + contextDog + "@Autowired注入： " + sessionDog;
    }

    @RequestMapping("/application")
    public String application() {
        Dog contextDog = context.getBean("applicationDog",Dog.class);
        return "contextDog: " + contextDog + "@Autowired注入： " + applicationDog;
    }
}
